package bean;

import java.util.*;

public class ApiGroup {
    private String applicationName;

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    private String safeMode;
    private String apiModule;
    private String apiService;
    //支持的http方法
    private List<String> supportHttpMethod = new ArrayList<>(1);

    private LinkedHashMap<String/*action*/, LinkedHashMap<String/*version*/, Api>> apiAction = new LinkedHashMap<>();

    @Override
    public String toString() {
        return "ApiGroup{" +
                "safeMode='" + safeMode + '\'' +
                ", apiModule='" + apiModule + '\'' +
                ", apiService='" + apiService + '\'' +
                ", supportHttpMethod=" + supportHttpMethod +
                ", apiAction=" + apiAction +
                '}';
    }

    public String getSafeMode() {
        return safeMode;
    }
    public void setSafeMode(String safeMode) {
        this.safeMode = safeMode;
    }

    public List<String> getSupportHttpMethod() {
        return supportHttpMethod;
    }

    public void setSupportHttpMethod(String[] supportHttpMethod) {
        for(String httpMethod: supportHttpMethod){
            this.supportHttpMethod.add(httpMethod);
        }
    }

    public String getApiModule() {
        return apiModule;
    }

    public void setApiModule(String apiModule) {
        this.apiModule = apiModule;
    }

    public String getApiService() {
        return apiService;
    }

    public void setApiService(String apiService) {
        this.apiService = apiService;
    }

    public LinkedHashMap<String, LinkedHashMap<String, Api>> getApiAction() {
        return apiAction;
    }

    public static class Api {
        //API注释
        private String comment;
        //API操作
        private String action;
        //API版本
        private String version;
        //请求参数
        private List<Param> requestParams = new ArrayList<>(2);
        //请求参数
        private List<Param> responseParams = new ArrayList<>(2);
        //系统响应信息
        private Map<String,String> returnCode = new HashMap<>(1);

        public Map<String, String> getReturnCode() {
            return returnCode;
        }

        public void setReturnCode(Map<String, String> returnCode) {
            this.returnCode = returnCode;
        }

        public void addRequestParam(Param param){
            this.requestParams.add(param);
        }
        public void addResponseParam(Param param){
            this.responseParams.add(param);
        }

        public List<Param> getRequestParams() {
            return requestParams;
        }

        public List<Param> getResponseParams() {
            return responseParams;
        }

        public String getComment() {
            return comment;
        }

        public void setComment(String comment) {
            this.comment = comment;
        }

        public String getAction() {
            return action;
        }

        public void setAction(String action) {
            this.action = action;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }

        @Override
        public String toString() {
            return "Api{" +
                    "comment='" + comment + '\'' +
                    ", action='" + action + '\'' +
                    ", version='" + version + '\'' +
                    ", requestParams=" + requestParams +
                    ", responseParams=" + responseParams +
                    '}';
        }

    }

    public static class Param{
        private String name;
        private boolean required;
        private String use;
        private String comment;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public boolean isRequired() {
            return required;
        }

        public void setRequired(boolean required) {
            this.required = required;
        }

        public String getUse() {
            return use;
        }

        public void setUse(String use) {
            this.use = use;
        }

        public String getComment() {
            return comment;
        }

        public void setComment(String comment) {
            this.comment = comment;
        }

        @Override
        public String toString() {
            return "Param{" +
                    "name='" + name + '\'' +
                    ", required=" + required +
                    ", use='" + use + '\'' +
                    ", comment='" + comment + '\'' +
                    '}';
        }
    }
}
